#ifndef __GUI_H__
#define __GUI_H__

#include <stdint.h>
#include <stdbool.h>

// 区域管理系统相关定义
#define MAX_REGIONS 16  // 最大支持的区域数量

// 区域状态枚举
typedef enum {
    REGION_INACTIVE = 0,    // 非活跃状态
    REGION_ACTIVE = 1,      // 活跃状态
    REGION_DIRTY = 2        // 需要刷新状态
} region_state_t;

// 颜色区域结构体
typedef struct {
    uint16_t x;             // 起始X坐标
    uint16_t y;             // 起始Y坐标
    uint16_t width;         // 宽度
    uint16_t height;        // 高度
    uint16_t color;         // 颜色值
    region_state_t state;   // 区域状态
    bool visible;           // 是否可见
    uint32_t last_update;   // 上次更新时间戳
} color_region_t;

// 区域管理器结构体
typedef struct {
    color_region_t regions[MAX_REGIONS];  // 区域数组
    uint8_t region_count;                 // 当前区域数量
    bool auto_refresh;                    // 自动刷新开关
    uint32_t frame_counter;               // 帧计数器
} region_manager_t;

void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void Draw_Circle(uint16_t x0,uint16_t y0,uint16_t fc,uint8_t r);
void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void LCD_ShowChar(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
void LCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size);
void LCD_Show2Num(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint8_t size,uint8_t mode);
void LCD_ShowString(uint16_t x,uint16_t y,uint8_t size,uint8_t *p,uint8_t mode);
void GUI_DrawFont16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
void GUI_DrawFont24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
void GUI_DrawFont32(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
void Show_Str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode);
void Gui_Drawbmp16(uint16_t x,uint16_t y,const unsigned char *p); //��ʾ40*40 QQͼƬ
void gui_circle(int xc, int yc,uint16_t c,int r, int fill);
void Gui_StrCenter(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode);
void LCD_DrawFillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);

// 区域管理系统函数声明
void Region_Manager_Init(void);
int Region_Add(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
bool Region_Remove(int region_id);
bool Region_Update(int region_id, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
bool Region_SetColor(int region_id, uint16_t color);
bool Region_SetVisible(int region_id, bool visible);
void Region_MarkDirty(int region_id);
void Region_MarkAllDirty(void);
void Region_Refresh_All(void);
void Region_Refresh_Dirty(void);
bool Region_IsOverlapping(uint16_t x1, uint16_t y1, uint16_t w1, uint16_t h1, 
                         uint16_t x2, uint16_t y2, uint16_t w2, uint16_t h2);
void Region_Demo_ColorfulBoxes(void);
void Region_Demo_MovingRects(void);
void Region_Demo_Rainbow(void);

// 批量刷新和DMA加速相关函数声明
void GUI_BatchWritePixels(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t *pixel_data);
void GUI_FastFill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color);
void GUI_DMA_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color);
void GUI_DMA_BatchWrite(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t *pixel_data);
void GUI_OptimizedFill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color);
void GUI_RegionBuffer_Init(void);
void GUI_RegionBuffer_Flush(void);
void GUI_Performance_Demo(void);
void GUI_Speed_Test(void);
void GUI_Performance_Demo_Advanced(void);
void GUI_NES_Optimized_Demo(void);

#endif

